package cn.hxzy.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

public class BigDecimalFormat extends JsonSerializer<BigDecimal> {

    private DecimalFormat df = new DecimalFormat("##.00");


    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (bigDecimal!=null){
            jsonGenerator.writeString(df.format(bigDecimal));
        }
    }
}
